<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/mainstyle.css" />
    <link rel="stylesheet" type="text/css" href="css/radiocheck.css" />
    <link rel="stylesheet" type="text/css" href="css/button.css" />
    <link rel="icon" href="image/logo.ico" type="image/x-icon">
    <title>疫苗预约</title>
    <style type="text/css">
        .clearfix:after {
        content: ".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;
        }
        #main_body_part{
            width: 90%; 
            margin-left: 3%;
            float: left;
            margin-top: 2rem;
        }
        #main_body_add{
            padding-top: 0.5rem;
            width: 12%;
            height: 10%;
            font-size: 1.3rem;
            float: left;
            
        }
        #main_body_name_input,#main_body_sex_input,#main_body_id_input{
            float: left;
            width: 50%;
            height: 10%;
           
        }
        #main_body_submit_button{
            margin: auto;
        }
        #add_name,#add_id{
            width: 100%;
            height: 2rem;
        }
        #type_input1{
            float: left;
            margin-top: 0.8rem;
            margin-right: 1rem;
        }
        #main_head_imgb{
            background-color: #ececee;
            border-radius: 50%;
        }
    </style>
    <?php
        function yes2(string $err){//信息插入成功时返回家人页面
            echo "<script>parent.location.href='main_family.php';alert('".$err."');</script>";
        }
        include_once 'api/DBcon.php';
        $result=false;
        $link=OpenDB();
        @session_start();
        $userName=$_SESSION['userName'];//用户名
        $headImgSrc=$_SESSION['imgsrc'];//头像路径
        $number=0;
        if(isset($_POST['submit'])&&$link){
            $name=$_FILES['add_id'];
            $id=$_POST['add_name'];  
            $idUser=$_SESSION['idUser'];
            if($id!=null&&$id!=""){
                $query="UPDATE user SET USERNAME='${id}' where idUser=\"${idUser}\";";
                $result = mysqli_query($link,$query);
                if(mysqli_affected_rows($link))
                    $number=1;
            }
            if($name['name']!=null&&$name['name']!=""){
                $src="image/".$name['name'];
                move_uploaded_file($name['tmp_name'],$src);
                
                $query="UPDATE user SET imgsrc='${src}' where idUser=\"${idUser}\";";
                $result = mysqli_query($link,$query);
                if(mysqli_affected_rows($link))
                    $number=1;
            }
            if($number){
                yes2("修改成功！");
            }
        }
            
    ?>
        
</head>
<body>
    <div id="left_part">
    <div id="navigationBar">
        <div id=logo>
            <img src="image/logo1.png" title="疫苗预约" id="logoimg"/>
            <img src="image/text.png" title="yuyue" id="logotext"/>
        </div>
        <div id="buttons">
            <a href="main_family.php">
            <div class="button" id="family" onmouseover="this.style.background='#84858d14'" onmouseout="this.style.background=''">
                <img src="image/jiaren.png" title="我的家人" id="icon"/>
                我的家人
            </div>
            </a>
            <a href="main_reservation.php">
            <div class="button" id="reservation" onmouseover="this.style.background='#84858d14'" onmouseout="this.style.background=''">
                <img src="image/yuyue.png" title="预约注射" id="icon"/>
                预约注射
            </div>
            </a>
            
            <a href="main_notice.php">
            <div class="button" id="notice" onmouseover="this.style.background='#84858d14'" onmouseout="this.style.background=''">
                <img src="image/zhuyi.png" title="注意事项" id="icon"/>
                注意事项
            </div>
            </a>
        </div>   
    </div>
    <div id="user">
        <img src="<?php echo $headImgSrc;?>" title="头像" id="headimg"/>
        <div id="userId"><?php echo $userName;?></div>
        <img src="image/dangan.png" title="注意事项" id="myId"/>
        
    </div>
    <a href="index.php"><div id="bottom">退出登录</div></a>
</div>
    <div id="main">
        
        <div id="main_head">
            <div id="main_head_text">账号信息></div>
            <div id="main_head_imgb"><img src="image/wenhua.jpeg" title="添加" id="main_head_icon"/></div>
        </div>
        
        <div id="main_body">
        <form action="" method="post" id="form1" enctype="multipart/form-data">
            <div id="main_body_part" class="clearfix">
                <div id="main_body_add">昵称：</div>
                <div id="main_body_name_input">
                    <input type="text" name="add_name" id="add_name" autocomplete="off"/>
                </div>
            </div>

            <div id="main_body_part">
                <div id="main_body_add">头像：</div>
                <div id="main_body_id_input">
                    <input type="file" name="add_id" id="add_id" autocomplete="off"/>
                </div>
            </div>

            <div id="main_body_part">
                    <div id="main_body_submit_button">
                        <button type="submit" name="submit" id="submit" value="resubmit" class="buttons green">确认修改</button>
                    </div>
            </div>
        </form>
        </div>
        <div id="main_bottom">
            <span>地址：武汉市东湖新技术开发区文华园路8号</span>
            <span>作者：文华学院信息学部计科1806刘昊天</span>
        </div>
    </div>
    
</body>
</html>